//
//  FPAddNewBankCardController.m
//  FinanceProject
//
//  Created by 陈显摆 on 2025/1/23.
//

#import "FPAddNewBankCardController.h"
#import "FPAuthenticationFooterView.h"
#import "FPAddNewBankCardHeader.h"
#import <Photos/PHPhotoLibrary.h>
#import <AVFoundation/AVCaptureDevice.h>
#import <AVFoundation/AVMediaFormat.h>

@interface FPAddNewBankCardController () <TTTAttributedLabelDelegate , UITextFieldDelegate , HJCActionSheetDelegate , UITableViewDelegate , UITableViewDataSource , UINavigationControllerDelegate, UIImagePickerControllerDelegate>

@property (nonatomic , strong) FPAuthenticationFooterView *footerView;
@property (nonatomic , strong) FPAddNewBankCardHeader *headerView;
@property (nonatomic , assign) BOOL isSelect;
@property (nonatomic , strong) NSMutableArray *protocolSource;
@property (nonatomic, strong) UIImagePickerController *imagePickerController;
@property (nonatomic , strong) NSString *bankName;
@property (nonatomic , strong) NSString *validToDate;
@property (nonatomic , strong) NSString *cardNumber;

@end

@implementation FPAddNewBankCardController

LazyLoadDataSource(protocolSource);

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    FPBaseTableViewCell *cell;
    
    if (!cell) {
        
        cell = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(FPBaseTableViewCell.class) owner:nil options:nil].lastObject;
    }
    
    cell.contentView.backgroundColor = MAIN_VIEW_BACKGROUND_COLOR;
    cell.backgroundColor = MAIN_VIEW_BACKGROUND_COLOR;
    
    return cell;
}

- (void)openCamereAction {
    
    [self.view endEditing:YES];
    HJCActionSheet *sheet = [[HJCActionSheet alloc] initWithDelegate:self CancelTitle:@"取消" OtherTitles:@"拍照" , @"相册", nil];
    [sheet show];
}

- (void)initUI {
    
    self.view.backgroundColor = MAIN_VIEW_BACKGROUND_COLOR;
    [self setTitle:@"添加银行卡" style:(XYCustomNavigationStyleWhite) hiddenBackBtn:NO];
    
    [self.view addSubview:self.tableView];
    self.tableView.backgroundColor = MAIN_VIEW_BACKGROUND_COLOR;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 2.f;
    
    self.headerView = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(FPAddNewBankCardHeader.class) owner:nil options:nil].lastObject;
    self.tableView.tableHeaderView = self.headerView;
    
    self.headerView.tf1.delegate = self;
    self.headerView.tf2.delegate = self;
    self.headerView.tf3.delegate = self;
    self.headerView.tf4.delegate = self;
    self.headerView.tf6.delegate = self;
    
    [self.headerView.camereImgView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openCamereAction)]];
    self.tableView.frame = CGRectMake(0.f, UIDevice.navigationFullHeight, SCREEN_WIDTH, SCREEN_HEIGHT - UIDevice.navigationFullHeight - 120.f - UIDevice.safeDistanceBottom);
    
    self.footerView = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(FPAuthenticationFooterView.class) owner:nil options:nil].lastObject;
    [self.view addSubview:self.footerView];
    self.footerView.frame = CGRectMake(0.f, SCREEN_HEIGHT - 120.f - UIDevice.safeDistanceBottom, SCREEN_WIDTH, 120.f);
    [self.footerView.nextBtn setTitle:@"添加账户" forState:(UIControlStateNormal)];
    self.footerView.backgroundColor = UIColor.clearColor;
    
    [self.footerView.selectImgView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectAction)]];
    [self.footerView.imgBackView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectAction)]];
    
    [self.headerView.codeBtn handleViewControlEvents:UIControlEventTouchUpInside withBlock:^{
       
        [self.view endEditing:YES];
        
        if ([self isValidParam]) {
         
            NSString *number = [FPUserModel AES256Encrypt:self.headerView.tf3.text];
            // 获取验证码
            [MBManager showLoading];
            [FPUserModel getMessageCodeWithPhoneNumber:number success:^(BOOL isSuccess, NSString * _Nonnull message, NSInteger code) {
                [MBManager hideLoading];
                
                if (code == 200) {
               
                    // 倒计时~
                    [self startCountDownTimer];
                }
                else {
                    
                    [self showText:message];
                }
                
            } failure:^(NSError * _Nonnull error) {
                [self showError:error];
            }];
        }
    }];
    
    [self.footerView.nextBtn handleViewControlEvents:UIControlEventTouchUpInside withBlock:^{
       
        // 添加~
        [self confirmAction];
    }];
    
    [self getProtocol];
}


- (BOOL)isValidBankCard:(NSString *)cardNumber {
    
    NSString *regex = @"^[1-9][0-9]{15,18}$";
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    return [predicate evaluateWithObject:cardNumber];
}

- (BOOL)isValidParam {
    
    if (self.headerView.tf1.text.length < 1) {
        
        [self.headerView.cardBackView shake];
        return NO;
    }
    
    if (![self isValidBankCard:self.headerView.tf1.text]) {
        
        [self showText:@"请检查卡号或补充完整"];
        [self.headerView.cardBackView shake];
        return NO;
    }
    
    if (self.headerView.tf2.text.length < 1) {
        
        [self.headerView.view2 shake];
        return NO;
    }
    
    if ([self.headerView.tf2.text containsString:@"支持"]) {
        
        [self showText:@"请检查卡号或补充完整"];
        [self.headerView.view2 shake];
        return NO;
    }
    
//        if (self.headerView.tf6.text.length < 1) {
//
//            [self.headerView.view6 shake];
//            return;
//        }
    
    if (self.headerView.tf3.text.length < 1) {
        
        [self.headerView.view3 shake];
        return NO;
    }
    
    return YES;
}

#pragma mark - 获取协议
- (void)getProtocol {
    
    [FPProtocolModel getProtocolWithType:(FPProtocolTypeBankCard) success:^(NSInteger code, NSString * _Nonnull message, NSArray *list) {
        [MBManager hideLoading];
        
        [self.protocolSource removeAllObjects];
        if (code == 200) {
            
            for (FPProtocolModel *model in list) {
                
                [self.protocolSource addObject:model];
            }
            
            NSMutableString *protocolStr = NSMutableString.string;
            
            for (FPProtocolModel *model in self.protocolSource) {
                
                [protocolStr appendFormat:@"%@",model.agreementName];
            }
            
            NSString *text = [NSString stringWithFormat:@"我已阅读并同意%@", protocolStr];
            
            NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:text];
            
            for (NSInteger i = 0; i < self.protocolSource.count; i ++) {
                
                FPProtocolModel *model = self.protocolSource[i];
                
                NSRange range = [text rangeOfString:[NSString stringWithFormat:@"%@", model.agreementName]];
                [NSString stringToAttribute:attStr color:MAIN_BLUE_COLOR range:range];
                
                [self.footerView.privacyLab addLinkToURL:[NSURL URLWithString:model.address] withRange:range];
            }
            
            self.footerView.privacyLab.attributedText = attStr;
            self.footerView.privacyLab.delegate = self;
        }
        
    } failure:^(NSError * _Nonnull error) {
        [MBManager hideLoading];
    }];
}

- (void)selectAction {
    
    [self.view endEditing:YES];
    
    FeedBackGeneratorAction
    
    self.isSelect = !self.isSelect;
    
    if (self.isSelect) {
     
        self.footerView.selectImgView.image = SELECT_IMG_BLUE;
    }
    else {
     
        self.footerView.selectImgView.image = UNSELECT_IMG;
    }
}

#pragma mark - TTTAttributedLabelDelegate 处理协议点击
- (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url {
 
//    [MBManager showText:url.absoluteString];
    for (FPProtocolModel *model in self.protocolSource) {
        
        if ([url.absoluteString isEqualToString:model.address]) {
            
            FPMainWebController *vc = [[FPMainWebController alloc] init];
            
            vc.model = model;
            vc.protocolType = FPProtocolTypeBankCard;
            
            [self.navigationController pushViewController:vc animated:YES];
            return;
        }
    }
}

#pragma mark - 开始倒计时 验证码
- (void)startCountDownTimer {
    
    [self.view endEditing:YES];
    
    NSDate *oldDate = [NSDate date];
    // 倒计时时间
    __block NSInteger timeOut = 60;
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
    
    dispatch_source_set_timer(_timer, dispatch_walltime(NULL, 0), 1.0 * NSEC_PER_SEC, 0);
    dispatch_source_set_event_handler(_timer, ^{
        
        // 倒计时结束
        if (timeOut <= 0) {
            
            // 再次获取
            dispatch_source_cancel(_timer);
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.headerView.codeBtn setTitle:@"获取验证码" forState:(UIControlStateNormal)];
                self.headerView.codeBtn.userInteractionEnabled = YES;
                self.headerView.codeBtn.enabled = YES;
                [self.headerView.codeBtn setTitleColor:MAIN_BLUE_COLOR forState:(UIControlStateNormal)];
            });
        }
        // 正在倒计时
        else {
            
            NSDate *newDate = [NSDate date];
            NSTimeInterval timeInterva = [newDate timeIntervalSinceDate:oldDate];
            int seconds2 = (60 -timeInterva);
            NSString *timeStr = [NSString stringWithFormat:@"%d",seconds2];
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.headerView.codeBtn setTitle:[NSString stringWithFormat:@"重新获取(%@)", timeStr] forState:UIControlStateNormal];
                self.headerView.codeBtn.userInteractionEnabled = NO;
                self.headerView.codeBtn.enabled = NO;
                [self.headerView.codeBtn setTitleColor:[UIColor hexColor:@"#999999"] forState:(UIControlStateNormal)];
            });
            //bug 解决
            if (seconds2 <= 1) {
                timeOut = 1;
            }
            timeOut--;
        }
    });
    dispatch_resume(_timer);
}


- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {

    if ([string isEqualToString:@""]) {
        
        return YES;
    }
    
    if ([textField isEqual:self.headerView.tf1]) {
        
        return textField.text.length < 21;
    }
    
    if ([textField isEqual:self.headerView.tf2]) {
        
        return textField.text.length < 18;
    }
    
    if ([textField isEqual:self.headerView.tf3]) {
        
        return textField.text.length < 11;
    }
    
    if ([textField isEqual:self.headerView.tf4]) {
        
        return textField.text.length < 4;
    }
    
    if ([textField isEqual:self.headerView.tf6]) {
        
        return textField.text.length < 20;
    }
    
    // 数字 检查字符串是否为数字
    NSCharacterSet *nonDigitCharacterSet = [[NSCharacterSet decimalDigitCharacterSet] invertedSet];
    if ([string rangeOfCharacterFromSet:nonDigitCharacterSet].location != NSNotFound) {
        
        return NO;  // 如果输入的字符不是数字，则不允许输入
    }
    
    return YES;
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    
    if ([textField isEqual:self.headerView.tf1]) {
        
        if (self.headerView.tf1.text.length < 1) {
            
            return;
        }
        
//        self.phoneNumber = self.loginView.popupView.phoneTF.text;
        // 获取所属银行  
        
        [MBManager showLoading];
        [FPBankCardModel getBankInfoWithCardNumber:self.headerView.tf1.text success:^(FPBankCardModel * _Nonnull model) {
            [MBManager hideLoading];
            
            self.headerView.tf2.text = model.bank;
            
        } failure:^(NSError * _Nonnull error) {
            [MBManager hideLoading];
        }];
        
    }
//    else if ([textField isEqual:self.tf3]) {
//        
////        self.SMSCode = self.loginView.popupView.codeTF.text;
//    }
}


#pragma mark - 添加卡
- (void)confirmAction {
    
    [self.view endEditing:YES];
    
    if (![self isValidParam]) {
        
        return;
    }
    
    if (self.headerView.tf1.text.length < 1) {
        
        FeedBackGeneratorAction
        [self.headerView.cardBackView shake];
        return;
    }
    
    if (self.headerView.tf2.text.length < 1) {
        
        FeedBackGeneratorAction
        [self.headerView.view2 shake];
        return;
    }
    
    // 非必填
//    if (self.tf6.text.length < 1) {
//        
//        FeedBackGeneratorAction
//        [self.view6 shake];
//        return;
//    }
    
    if (self.headerView.tf3.text.length < 1) {
        
        FeedBackGeneratorAction
        [self.headerView.view3 shake];
        return;
    }
    
    if (self.headerView.tf4.text.length < 1) {
        
        FeedBackGeneratorAction
        [self.headerView.view4 shake];
        return;
    }
    
    if (self.isSelect == NO) {
        
        [FPBaseProtocolView showWithText:self.protocolSource onAction:^(NSUInteger index) {
            
            if (index == 1001) {
                
                // 拒绝
            }
            else {
                
                [self selectAction];
            }
            
        } protocolDidSelectAction:^(FPProtocolModel * _Nonnull model) {
            
//                NSLog(@"%@",model.agreementName);
            FPMainWebController *vc = [[FPMainWebController alloc] init];
            vc.model = model;
            vc.protocolType = FPProtocolTypeLogin;
            [self.navigationController pushViewController:vc animated:YES];
        }];
        
//        FeedBackGeneratorAction
//        [self.footerView.privacyLab shake];
        return;
    }
    
    NSString *enStr = [FPUserModel AES256Encrypt:self.headerView.tf1.text];
    NSString *phoneNo = [FPUserModel AES256Encrypt:self.headerView.tf3.text];
    
    NSMutableDictionary *param = APIClient.creatAPIDictionary;
    
    [param setObject:enStr forKey:@"bankCard"]; // 银行卡号 加密
    [param setObject:self.headerView.tf2.text forKey:@"bankName"]; // 所属银行
    [param setObject:phoneNo forKey:@"phone"]; // 手机号 加密
    [param setObject:self.headerView.tf4.text forKey:@"code"]; // 验证码
    
    if (self.headerView.tf6.text.length) {
        
        [param setObject:self.headerView.tf6.text forKey:@"openBank"]; // 开户行
    }
    
    [MBManager showLoading];
    [FPBankCardModel saveBankCardWithParam:param success:^(NSInteger code, NSString * _Nonnull message) {
        [MBManager hideLoading];
        
//         [self showText:@"验证码错误"];
        if (code == 200) {
            
            [self showText:@"添加成功"];
            [self performSelector:@selector(backAction) withObject:nil afterDelay:1.5f];
//            [[NSNotificationCenter defaultCenter] postNotificationName:FPBankCardAddSuccessNotification object:nil];
            
            [self signProtocolWithParams:self.protocolSource];
        }
        else {
            
            [self showText:message];
        }
        
    } failure:^(NSError * _Nonnull error) {
        [self showError:error];
    }];
}

- (void)backAction {
    
    self.bankCardBlock();
    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark - 银行卡识别处理
- (void)actionSheet:(HJCActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    
    [self.view endEditing:YES];
    
    UIImagePickerController *imgPC = [[UIImagePickerController alloc] init];
    imgPC.delegate = self;
    
    if (buttonIndex == 1) {
        
        // 判断设备是否有相机
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            
            self.imagePickerController = [[UIImagePickerController alloc] init];
            self.imagePickerController.delegate = self;  // 设置代理
            self.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;  // 设置为相机
            self.imagePickerController.allowsEditing = YES;  // 是否允许编辑（裁剪）
            
            // 打开相机
            [self presentViewController:self.imagePickerController animated:YES completion:nil];
        }
        else {
            // 提示用户设备没有相机
//            NSLog(@"设备没有相机");
            [self showText:@"设备不支持相机"];
        }
    }
    else if (buttonIndex == 2) {
        
        PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
        
        dispatch_async(dispatch_get_main_queue(), ^{
            if (status == PHAuthorizationStatusRestricted || status == PHAuthorizationStatusDenied) {
                // 无权限
                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"无访问权限" message:@"是否跳转相机设置？" preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                }];
                UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    
                    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
                }];
                [alert addAction:cancel];
                [alert addAction:action];
                [self presentViewController:alert animated:YES completion:^{
                }];
            }
            else {
                
                imgPC.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){
                    
                    [self presentViewController:imgPC animated:YES completion:nil];
                }
            }
        });
    }
}

// UIImagePickerControllerDelegate 方法：取消拍照时调用此方法
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    // 关闭相机界面
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
    
    UIImage *image = info[UIImagePickerControllerOriginalImage];
    
    NSData *data = [self zipNSDataWithImage:image]; //UIImagePNGRepresentation(image);
    
    [picker dismissViewControllerAnimated:YES completion:nil];
    
    [self uploadImg:data]; //UIImagePNGRepresentation(image)
}

- (NSInteger)getRandomNumber:(NSInteger)from to:(NSInteger)to {
    
    return (NSInteger)(from + (arc4random() % (to - from + 1)));
}

#pragma mark - 压缩图片
- (NSData *)zipNSDataWithImage:(UIImage *)sourceImage {
    //进行图像尺寸的压缩
    CGSize imageSize = sourceImage.size;//取出要压缩的image尺寸
    CGFloat width = imageSize.width;    //图片宽度
    CGFloat height = imageSize.height;  //图片高度
    //1.宽高大于1280(宽高比不按照2来算，按照1来算)
    if (width>1280||height>1280) {
        if (width>height) {
            CGFloat scale = height/width;
            width = 1280;
            height = width*scale;
        }else{
            CGFloat scale = width/height;
            height = 1280;
            width = height*scale;
        }
        //2.宽大于1280高小于1280
    }else if(width>1280||height<1280){
        CGFloat scale = height/width;
        width = 1280;
        height = width*scale;
        //3.宽小于1280高大于1280
    }else if(width<1280||height>1280){
        CGFloat scale = width/height;
        height = 1280;
        width = height*scale;
        //4.宽高都小于1280
    }else{
    }
    UIGraphicsBeginImageContext(CGSizeMake(width, height));
    [sourceImage drawInRect:CGRectMake(0,0,width,height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    //进行图像的画面质量压缩
    NSData *data=UIImageJPEGRepresentation(newImage, 1.0);
    if (data.length>100*1024) {
        if (data.length>1024*1024) {//1M以及以上
            data=UIImageJPEGRepresentation(newImage, 0.7);
        }else if (data.length>512*1024) {//0.5M-1M
            data=UIImageJPEGRepresentation(newImage, 0.8);
        }else if (data.length>200*1024) {
            //0.25M-0.5M
            data=UIImageJPEGRepresentation(newImage, 0.9);
        }
    }
    return data;
}

# pragma mark - 上传图片
- (void)uploadImg:(NSData *)imageData {
    
    [MBManager showLoading];
    NSMutableDictionary *headers = NSMutableDictionary.dictionary;
    [headers setValue:@"application/json" forKey:@"Content－Type"];
    [headers setValue:@"user" forKey:@"X-User-Type"];
    
    if (FPUserModel.globalToken.length) {
        
        [headers setValue:FPUserModel.globalToken forKey:@"token"];
    }
    
    // 1. 创建上传请求的 URL
    NSURL *url = [NSURL URLWithString:[MAIN_URL stringByAppendingString:UPLOAD_BANK_CARD_URL]];
    
    // 2. 创建 AFHTTPSessionManager 实例
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    // 3. 设置请求头类型，告诉服务器我们传送的是 multipart/form-data 格式
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    [manager.requestSerializer setValue:@"multipart/form-data" forHTTPHeaderField:@"Content-Type"];
    
    [manager setDataTaskDidReceiveDataBlock:^(NSURLSession * _Nonnull session, NSURLSessionDataTask * _Nonnull dataTask, NSData * _Nonnull data) {
    
        NSLog(@"Request URL: %@", dataTask.originalRequest.URL.absoluteString);
    }];
    
    // 4. 设置图片上传的表单字段，使用 multipart/form-data 编码
    [manager POST:url.absoluteString parameters:nil headers:headers constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        
        [formData appendPartWithFileData:imageData name:@"file" fileName:@"image.jpg" mimeType:@"image/jpeg"];
        
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        
        // 进度回调
        NSLog(@"Upload Progress: %.2f%%", uploadProgress.fractionCompleted * 100);
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        [MBManager hideLoading];
        
        if ([responseObject isKindOfClass:NSDictionary.class]) {
            
            NSInteger code = [[responseObject objectForKey:@"code"] integerValue];
            
            if (code == 200) {
                
//                [self updoadFaild];
                self.bankName = [responseObject objectForKey:@"data"][@"bankName"];
                self.cardNumber = [responseObject objectForKey:@"data"][@"cardNumber"];
                self.cardNumber = [FPUserModel AES256Decrypt:self.cardNumber];
                self.validToDate = [responseObject objectForKey:@"data"][@"validToDate"];
                
                [self uploadSuccess];
            }
        }
        else {
//            [self showText:@"上传失败"];
            
            [self updoadFaild];
        }
        // 上传成功
        NSLog(@"Upload Success: %@", responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [self showError:error];
        // 上传失败
        NSLog(@"Upload Failed: %@", error.localizedDescription);
    }];
}

- (void)updoadFaild {
    
    [self showText:@"识别失败，请重试"];
}

- (void)uploadSuccess {
    
    self.headerView.tf1.text = self.cardNumber;
    self.headerView.tf2.text = self.bankName;
}


@end
